//
//  SKUDetailReceiveTBCell.m
//  ZITHER
//
//  Created by weixin on 2018/8/17.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "SKUDetailReceiveTBCell.h"

@implementation SKUDetailReceiveTBCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.btnDone setCornerRadiusWithRadius:8 isMasks:YES];
}

- (IBAction)notInteresy:(id)sender {
    
    NSLog(@"不感兴趣");
    
    [[serviceDefualt loadNoInterestPrice:self.modelAccept.id reponseObjctClass:nil]subscribeNext:^(ResponseData* x) {
        if (x.success) {
            [Tools showTips:@"设置不感兴趣成功"];
            if (self.blockRemoveCell) {
                self.blockRemoveCell(self.idnexCell);
            }
        }else{
             [Tools showTips:x.errorInfo];
        }
    }];
    
}

- (IBAction)done:(id)sender {
    NSLog(@"接受报价");
    if (!kUSER_INFO_MANAGER.userIsLogin) {
        [Tools pushSinge];
        return ;
    }
    if ([self.indexType isEqualToString:@"0"]) {
        //提醒商家向我报价
        [[serviceDefualt loadRemindBizSourcePrice:self.model.goodsSourceId reponseObjctClass:nil]subscribeNext:^(ResponseData* x) {
            if (x.success) {
                self.btnDone.enabled = NO;
                [Tools showTips:@"提醒商家成功"];
                self.btnDone.backgroundColor = baseColorLight;

            }else{
                self.btnDone.enabled = YES;
                 [Tools showTips:x.errorInfo];
            }
        }];
    }else if([self.indexType isEqualToString:@"1"] ||[self.indexType isEqualToString:@"3"] ){
        [[serviceDefualt loadacceptGoodsPrice:self.modelAccept.goodsId priceId:self.modelAccept.id reponseObjctClass:nil]subscribeNext:^(ResponseData * x) {
            if (x.success) {
                self.btnDone.enabled = NO;
                [Tools showTips:@"接受报价成功"];
                self.btnDone.backgroundColor = baseColorLight;
                [self.btnDone setTitle:@"已接受报价" forState:UIControlStateDisabled];

            }else{
                self.btnDone.enabled = YES;
                
                 [Tools showTips:x.errorInfo];
            }
        }];
    }else{
        //提醒商家向我报价
        if (self.IsEnquiry) {
            
            [self showQMUIAlertAction];
            
        }else{
            [[serviceDefualt loadRemindBizSourcePrice:self.model.goodsSourceId reponseObjctClass:nil]subscribeNext:^(ResponseData* x) {
                if (x.success) {
                    self.btnDone.enabled = NO;
                    [Tools showTips:@"提醒商家成功"];
                    self.btnDone.backgroundColor = baseColorLight;
                }else{
                    self.btnDone.enabled = YES;
                     [Tools showTips:x.errorInfo];
                }
            }];
        }
   
    }
}


-(void)showQMUIAlertAction{
    QMUIAlertAction *ac1 = [QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
        
    }];
    
    QMUIAlertAction *ac2 = [QMUIAlertAction actionWithTitle:@"确认" style:QMUIAlertActionStyleDestructive handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
        __weak __typeof(self)weakSelf = self;
        [[serviceDefualt loadopenEnquiry:self.goodid]subscribeNext:^(ResponseData* x) {
            if (x.success) {
                [kUSER_INFO_MANAGER MyList];
                [Tools showTips:@"开启询价成功"];
                self.IsEnquiry = NO;
                if (weakSelf.blockChangeIsEnquiry) {
                    weakSelf.blockChangeIsEnquiry();
                }
            }else{
                 [Tools showTips:x.errorInfo];
            }
        }];
        
    }];
    
    QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"确定开启询价?" message:@"未开启询价 无法提醒商家 是否开启询价" preferredStyle:QMUIAlertControllerStyleAlert];
    [alertController addAction:ac1];
    [alertController addAction:ac2];
    
    [alertController showWithAnimated:YES];
}


-(void)setModel:(OpenGoodsSourceInfoModel *)model{
    _model = model;
    if ([model.isRemind isEqualToString:@"0"]) {
        self.btnDone.enabled = YES;
        self.btnDone.backgroundColor = baseColorTheme;

    }else{
        self.btnDone.enabled = NO;
        self.btnDone.backgroundColor = baseColorLight;
    }
    
    self.textView.text = model.sourceDesc;
    CGRect frame = self.textView.frame;
    frame.size.height = [NSString textHeight:self.textView.text font:16 width:self.textView.frame.size.width];
    NSLog(@"frame.size.height == %f",frame.size.height);
    self.textView.frame = frame;
    
    
     if (self.model.fileList.count>0) {
        self.scrollview.frame = CGRectMake(0,CGRectGetMaxY(self.textView.frame)+25 , kScreenW-15,60);
        self.scrollview.hidden = NO;
        [self.scrollview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        self.scrollview.contentSize = CGSizeMake(self.model.fileList.count*68+15,0);
        
        for (int j = 0; j<self.model.fileList.count; j++) {
            UIImageView * imageV = [[UIImageView alloc]initWithFrame:CGRectMake(j*68+15,0, 60,60)];
            [imageV setCornerRadiusWithRadius:5 isMasks:YES];
            imageV.backgroundColor = [UIColor whiteColor];
            imageV.contentMode = UIViewContentModeScaleAspectFill;
            
            NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,self.model.fileList[j]];
            
            [imageV sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"watchSmale"]];
            
            [self.scrollview addSubview:imageV];
        }
        
    }else{
        self.scrollview.hidden = YES;
    }
}

-(void)setModelAccept:(AcceptPriceListModel *)modelAccept{
    _modelAccept = modelAccept;
   
    if ([modelAccept.sourceStatus isEqualToString:@"0"]) {
        self.btnDone.enabled = YES;
        self.btnDone.backgroundColor = baseColorTheme;
    }else{
        self.btnDone.enabled = NO;
        self.btnDone.backgroundColor = baseColorLight;
        [self.btnDone setTitle:@"已下架" forState:UIControlStateDisabled];
    }
    
    if (modelAccept.goodsSourcePrice.length>0) {
        self.price.text = modelAccept.goodsSourcePrice;
    }else{
        self.price.text = modelAccept.goodSourcePrice;
    }
    

    self.textView.text = modelAccept.sourceDesc;
    CGRect frame = self.textView.frame;
    frame.size.height = [NSString textHeight:self.textView.text font:16 width:self.textView.frame.size.width];
    NSLog(@"frame.size.height == %f",frame.size.height);
    self.textView.frame = frame;
    
    
    if (self.modelAccept.fileList.count>0) {
        self.scrollview.frame = CGRectMake(0,CGRectGetMaxY(self.textView.frame)+25 , kScreenW-15,60);
        self.scrollview.hidden = NO;
        [self.scrollview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        self.scrollview.contentSize = CGSizeMake(self.modelAccept.fileList.count*68+15,0);
        
        for (int j = 0; j<self.modelAccept.fileList.count; j++) {
            UIImageView * imageV = [[UIImageView alloc]initWithFrame:CGRectMake(j*68+15,0, 60,60)];
            [imageV setCornerRadiusWithRadius:5 isMasks:YES];
            imageV.backgroundColor = [UIColor whiteColor];
            imageV.contentMode = UIViewContentModeScaleAspectFill;
            
            NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,self.modelAccept.fileList[j]];
            
            [imageV sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"watchSmale"]];
            
            [self.scrollview addSubview:imageV];
        }
        
    }else{
        self.scrollview.hidden = YES;
    }
    

    
}



-(void)setTypeCell:(BOOL)typeCell{
    _typeCell = typeCell;
    if (!typeCell) {
        [self.btnDone setTitle:@"提醒商家向我报价" forState:UIControlStateNormal];
        [self.btnDone setTitle:@"已提醒商家向我报价" forState:UIControlStateDisabled];
    }
    else{
        [self.btnDone setTitle:@"接受报价" forState:UIControlStateNormal];
        [self.btnDone setTitle:@"已接受报价" forState:UIControlStateDisabled];
    }
}





//-(UIScrollView *)scrollview{
//    if (!_scrollview) {
//        _scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(self.textView.frame)+35 , kScreenW,60)];
//        _scrollview.bounces = NO;
//        _scrollview.showsHorizontalScrollIndicator = NO;
//        _scrollview.contentSize = CGSizeMake(kScreenW*3,0);
//        _scrollview.bounces = NO; // 默认为YES 取消设置NO
//        // 当bounces属性为NO时，以下两个属性设置无效
//        _scrollview.alwaysBounceHorizontal = YES; // 水平方向弹簧效果
//        _scrollview.alwaysBounceVertical = YES; // 垂直方向弹簧效果
//        _scrollview.decelerationRate = 0.1; // 值域 0~1 值越小减速停止的时间越短
//        _scrollview.backgroundColor = [UIColor whiteColor];
//        [self addSubview:_scrollview];
//    }
//    return _scrollview;
//}
@end
